package com.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.dao.UsersDAO;
import com.model.Users;
import com.opensymphony.xwork2.ModelDriven;

public class UsersAction implements ModelDriven<Users>, ServletRequestAware {
	private Users users;
	private HttpServletRequest request;
	UsersDAO usersDAO=new UsersDAO();
	public String login() throws Exception {

		if (usersDAO.get(users.getUsername(),users.getPassword())!=null) {
			return "success";
		} else {
			return "error";
		}
	}
	public String show() {
		List<Users> userslist = usersDAO.getAll();
		request.setAttribute("userslist", userslist);
		return "success";
	}

	public Users getUsers() {
		return users;
	}

	public void setUsers(Users users) {
		this.users = users;
	}

	@Override
	public Users getModel() {
		users=new Users();
		return this.getUsers();
	}
	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		this.request=arg0;
	}

}
